package com.top4create.model;

import com.top4create.model.BaseObject;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableComponent;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;

import javax.xml.bind.annotation.XmlRootElement;

import java.io.Serializable;

@Entity
@Table(name="position",catalog="top4create_test")
@Searchable
@XmlRootElement
public class Position extends BaseObject implements Serializable {
    private Long id;
    private Company company;
    private Long amount;
    private String description;
    private String exprience;
    private String location;
    private String salary;
    private String school;
    private String title;
    private Set<FavouratePosition> favouratePositions = new HashSet<FavouratePosition>(0);

    @Id @GeneratedValue(strategy=IDENTITY) @SearchableId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="com_id")
    public Company getCompany() {
        return this.company;
    }
    
    public void setCompany(Company company) {
        this.company = company;
    }
    
    @Column(name="amount")
    @SearchableProperty
    public Long getAmount() {
        return this.amount;
    }
    
    public void setAmount(Long amount) {
        this.amount = amount;
    }
    
    @Column(name="description", length=1000)
    @SearchableProperty
    public String getDescription() {
        return this.description;
    }
    
    public void setDescription(String description) {
        this.description = description;
    }
    
    @Column(name="exprience", length=50)
    @SearchableProperty
    public String getExprience() {
        return this.exprience;
    }
    
    public void setExprience(String exprience) {
        this.exprience = exprience;
    }
    
    @Column(name="location", length=50)
    @SearchableProperty
    public String getLocation() {
        return this.location;
    }
    
    public void setLocation(String location) {
        this.location = location;
    }
    
    @Column(name="salary", length=50)
    @SearchableProperty
    public String getSalary() {
        return this.salary;
    }
    
    public void setSalary(String salary) {
        this.salary = salary;
    }
    
    @Column(name="school", length=50)
    @SearchableProperty
    public String getSchool() {
        return this.school;
    }
    
    public void setSchool(String school) {
        this.school = school;
    }
    
    @Column(name="title", length=50)
    @SearchableProperty
    public String getTitle() {
        return this.title;
    }
    
    public void setTitle(String title) {
        this.title = title;
    }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="position")
    public Set<FavouratePosition> getFavouratePositions() {
        return this.favouratePositions;
    }
    
    public void setFavouratePositions(Set<FavouratePosition> favouratePositions) {
        this.favouratePositions = favouratePositions;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Position pojo = (Position) o;

        if (company != null ? !company.equals(pojo.company) : pojo.company != null) return false;
        if (amount != null ? !amount.equals(pojo.amount) : pojo.amount != null) return false;
        if (description != null ? !description.equals(pojo.description) : pojo.description != null) return false;
        if (exprience != null ? !exprience.equals(pojo.exprience) : pojo.exprience != null) return false;
        if (location != null ? !location.equals(pojo.location) : pojo.location != null) return false;
        if (salary != null ? !salary.equals(pojo.salary) : pojo.salary != null) return false;
        if (school != null ? !school.equals(pojo.school) : pojo.school != null) return false;
        if (title != null ? !title.equals(pojo.title) : pojo.title != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (company != null ? company.hashCode() : 0);
        result = 31 * result + (amount != null ? amount.hashCode() : 0);
        result = 31 * result + (description != null ? description.hashCode() : 0);
        result = 31 * result + (exprience != null ? exprience.hashCode() : 0);
        result = 31 * result + (location != null ? location.hashCode() : 0);
        result = 31 * result + (salary != null ? salary.hashCode() : 0);
        result = 31 * result + (school != null ? school.hashCode() : 0);
        result = 31 * result + (title != null ? title.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("company").append("='").append(getCompany()).append("', ");
        sb.append("amount").append("='").append(getAmount()).append("', ");
        sb.append("description").append("='").append(getDescription()).append("', ");
        sb.append("exprience").append("='").append(getExprience()).append("', ");
        sb.append("location").append("='").append(getLocation()).append("', ");
        sb.append("salary").append("='").append(getSalary()).append("', ");
        sb.append("school").append("='").append(getSchool()).append("', ");
        sb.append("title").append("='").append(getTitle()).append("', ");
        
        sb.append("]");
      
        return sb.toString();
    }

}
